import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";
import AdminLayout from "../pages/admin/layout.vue"
//固定路由
const defaultRouterList: Array<RouteRecordRaw> = [
    {
        path: '/',
        redirect: '/admin/my/info',
    },
    {
        path: '/login',
        name: 'login',
        meta: {title: '登录账号'},
        component: () => import('../pages/login/index.vue'),
    },
    {
        path: '/admin',
        name: 'admin',
        component: AdminLayout,
        children: [
            {
                path: '404',
                name: '404',
                meta: {title: '页面找不到啦'},
                component: () => import('../pages/admin/404.vue')
            },
            {
                path: 'my',
                children: [
                    {
                        path: 'info',
                        name: 'my_info',
                        meta: {title: '我的信息'},
                        component: () => import('../pages/admin/my/info.vue')
                    }
                ]
            },
        ]
    },
    {
        path: '/:w*',
        redirect: '/admin/404',
    }
]

export const allRoutes = [...defaultRouterList]

const router = createRouter({
    history: createWebHashHistory(),
    routes: allRoutes,
})

router.beforeResolve(async (to, from) => {
    // @ts-ignore
    document.title = `${to.meta.title}：${to.name}`
})

export default router